<?php
error_reporting( E_ALL&~E_NOTICE );
ini_set( 'display_errors', 'off' );//屏蔽错误和警告提示
include("../mysql.php");
if(isset($_POST['adminpwd']) and isset($_POST['map']) and isset($_POST['npcname']) and isset($_POST['npcdesc']) and isset($_POST['npcpath']))
{
if($_POST['adminpwd']!="dashen"){
    //echo "无权操作";
    exit;
}    
$map=$_POST['map'];
$npcname=$_POST['npcname'];
$npcdesc=$_POST['npcdesc'];
$npcpath=$_POST['npcpath'];


$check="SELECT * FROM `xuanhong` WHERE `map` = '$map' AND `npcname` = '$npcname' AND `npcdesc` = '$npcdesc' AND `npcpath` = '$npcpath'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["map"]){
    echo "操作失败，已经有该条数据了";
    exit;
}
$check="SELECT * FROM `xuanhong` WHERE `map` = '$map' AND `npcname` = '$npcname' AND `npcpath` = '$npcpath'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["map"]){
    $old_npcdesc=$row["npcdesc"];
    $old_path=$row["npcpath"];
    if($npcdesc!=$old_npcdesc){
        $mysql="UPDATE `xuanhong` SET `npcdesc` = '$npcdesc' WHERE `npcdesc` ='$old_npcdesc' and `npcpath` ='$old_path';";
        mysql_query($mysql);
    }
    if($npcpath!=$old_path){
        $mysql="UPDATE `xuanhong` SET `npcpath` = '$npcpath' WHERE `npcdesc` ='$npcdesc' and `npcpath` ='$old_path';";
        mysql_query($mysql);
    }
    exit;
}
$sql="alter table `xuanhong` AUTO_INCREMENT=1";
mysql_query($sql);  //序列号自动归1
$mysql="INSERT INTO `xuanhong` (`id`, `map`, `npcname`, `npcdesc`, `npcpath`) VALUES (NULL, '$map', '$npcname', '$npcdesc', '$npcpath');";
//$mysql="INSERT INTO `eyuyan`.`xuanhong` (`id`, `map`, `npcname`, `npcdesc`, `npcpath`) VALUES (NULL, '得到的589', '得到的', '豆豆564', null)";
mysql_query($mysql);
echo "新增成功一条数据为:[$map,$npcname,$npcdesc,$npcpath]";
//echo "$mysql";
}
else{
    echo "无权访问";
}
?>